import 'package:flutter/material.dart';

import 'package:Second/namedrouter/page/Form.dart';
import 'package:Second/namedrouter/page/Search.dart';
import 'package:Second/namedrouter/Tabs.dart';

final routes = {
  "/": (context) => Tabs(),
  "/form": (context, {arguments}) => FormPage(
        "我是静态传入的 ",
        arguments: arguments,
      ),
  "/search": (context) => SearchPage()
};

Route? onGenerateRoute(RouteSettings settings) {
  //获取的跳转命名路由名称
  final String? name = settings.name;
  //获取到配置的Page
  final Function pageContentBuilder = routes[name] as Function;

  if (pageContentBuilder != null) {
    //获取参数，参数key是传入时的名称，所以需要约定如下使用时候的传参示例
    //Navigator.of(context).pushNamed('/form', arguments: {"id": "动态传入的ID"});
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
}
